package com.ebupt.migu.music.propagate.controller;

import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.common.util.ReqestParamUtil;
import com.ebupt.migu.music.propagate.pojo.dto.StrategyDto;
import com.ebupt.migu.music.propagate.pojo.dto.StrategyQueryDto;
import com.ebupt.migu.music.propagate.service.PropagateManageService;
import com.ebupt.migu.music.system.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author tz
 */
@Slf4j
@RestController
@RequestMapping("/propagate")
public class PropagateManageController {

    @Resource
    private PropagateManageService propagateManageService;
    @Resource
    private HttpServletRequest request;
    @Resource
    private HttpServletResponse response;
    /**
     * 文件上传
     * @param file
     * @return
     */
    @PostMapping(value = "/upload")
    public ResultObject uploadFile(@RequestParam("file") MultipartFile file) {
        return propagateManageService.uploadFile(file);
    }

    /**
     * 文件下载
     * @param fileName
     * @param filePath
     * @return
     */
    @GetMapping(value = "/downFile")
    public void download(@RequestParam("fileName") String fileName,@RequestParam("filePath") String filePath) throws IOException {
        propagateManageService.download(fileName,filePath,response);
    }

    /**
     * 创建或更新策略
     * @return
     */
    @PostMapping("/createOrUpdate")
    public ResultObject createOrUpdate(@RequestBody StrategyDto dto) {
        SysUser sysUser = ReqestParamUtil.userInfo(request);
        return propagateManageService.createOrUpdate(dto,sysUser);
    }

    /**
     * 查询策略列表
     * @return
     */
    @PostMapping("/qryList")
    public ResultObject qryList(@RequestBody StrategyQueryDto dto) {
        return propagateManageService.qryList(dto);
    }

    /**
     * 查询策略详情
     * @return
     */
    @GetMapping("/qryById")
    public ResultObject qryById(@RequestParam("id") Integer id) {
        return propagateManageService.qryById(id);
    }

    /**
     * 修改策略状态
     * @return
     */
    @PostMapping("/modifyStatus")
    public ResultObject modifyStatus(@RequestParam("id") Integer id,@RequestParam("status") Integer status) {
        return propagateManageService.modifyStatus(id,status);
    }

}